package com.macro.mall.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsTodayMorningExpressParam;
import com.macro.mall.model.BmsTodayMorningExpress;
import com.macro.mall.service.BmsTodayMorningExpressService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;
import java.util.UUID;

/**
 * 今日早报
 * @author ASUS
 *
 */
@Controller
@Api(tags = "BmsTodayMorningExpress")
@Tag(name = "BmsTodayMorningExpress", description = "今日早报")
@RequestMapping("/todayMorningExpress")
public class BmsTodayMorningExpressController {
    
    @Autowired
    private BmsTodayMorningExpressService bmsTodayMorningExpressService;
    
    /**
     * 根据id获取今日早报信息
     * @param id
     * @return
     */
//    @ApiOperation("根据id获取今日早报信息")
//    @RequestMapping(value = "/getOne", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult<BmsTodayMorningExpress> getOneTodayMorningExpress (@RequestParam String id){
//        BmsTodayMorningExpress bmsTodayMorningExpress = bmsTodayMorningExpressService.getOneTodayMorningExpress(id);
//        return CommonResult.success(bmsTodayMorningExpress);
//    }

    @ApiOperation("根据id获取今日早报")
    @RequestMapping(value = "/getOne",method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsTodayMorningExpress> getOneTodayMorningExpress(@RequestParam String id){
        BmsTodayMorningExpress bmsTodayMorningExpress = bmsTodayMorningExpressService.getOneTodayMorningExpress(id);
        return  CommonResult.success(bmsTodayMorningExpress);
    }
    /**
     * 分页查询今日早报信息
     * @param query
     * @return
     */
    @ApiOperation("分页查询今日早报信息")
    @RequestMapping(value = "/getAll", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsTodayMorningExpress>> getALLTodayMorningExpress (@RequestBody BmsTodayMorningExpressParam bmsTodayMorningExpressParam){
        List<BmsTodayMorningExpress> bmsTodayMorningExpressList = bmsTodayMorningExpressService.getAllTodayMorningExpress(bmsTodayMorningExpressParam);
        return CommonResult.success(CommonPage.restPage(bmsTodayMorningExpressList));
    }
    
    /**
     * 添加今日早报信息
     * @param query
     * @return
     */
//原代码
//    @ApiOperation("添加今日早报")
//    @RequestMapping(value = "/create", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult<?> create(@RequestBody BmsTodayMorningExpressParam bmsTodayMorningExpressParam) {
//        int count = bmsTodayMorningExpressService.create(bmsTodayMorningExpressParam);
//        if (count > 0) {
//            return CommonResult.success(count);
//        } else {
//            return CommonResult.failed();
//        }
//    }
    @ApiOperation("添加今日早报")
    @RequestMapping(value = "/create",method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsTodayMorningExpressParam bmsTodayMorningExpressParam){
        //调用添加方法
        int count = bmsTodayMorningExpressService.create(bmsTodayMorningExpressParam);
        //如果count>0说明添加成功
        if(count > 0){
            return  CommonResult.success(count);
        }else {
            return CommonResult.failed();
        }
    }
    
    @ApiOperation("删除今日早报")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestParam("ids") List<UUID> ids) {
        int count = bmsTodayMorningExpressService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    
    @ApiOperation("编辑今日早报")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsTodayMorningExpressParam bmsTodayMorningExpressParam) {
        int count = bmsTodayMorningExpressService.update(bmsTodayMorningExpressParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
}
